Platform Explorer / Nuxeo Platform 2021.63

Extension point operation

Documentation

    <scriptedOperation id="Scripting.HelloWorld">
        <inputType>string</inputType>
        <outputType>string</outputType>
        <param name="lang" type="string"/>
        <script>
          function run(input, params) {
          if (params.lang === "fr") {
          return "Bonjour " + input;
          } else {
          return "Hello " + input;
          }
          }
        </script>
    </scriptedOperation>

Contribution Descriptors

  • Class: org.nuxeo.automation.scripting.internals.ScriptingOperationDescriptor

Existing Contributions

Contributions are presented in the same order as the registration order on this extension point. This order is displayed before the contribution name, in brackets.

  • nuxeo-salesforce-core-2021.2.0.jar /OSGI-INF/automation-contrib.xml
    <extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
        <scriptedOperation id="Salesforce.TouchSFLibrary">
          <inputType>document</inputType>
          <outputType>document</outputType>
          <category>javascript</category>
          <param name="update" type="Boolean"/>
          <param name="record" type="Object"/>
          <script>
            <![CDATA[function run(input, params) {
                var sfobject = JSON.parse(params.record);
                var update = params.update;
                var properties = {
                     "dc:title" : sfobject.Name,
                     "sf:objectId" : sfobject.Id,
                     "sf:objectType" : sfobject.sobjectType,
                     "dc:description" : sfobject.Description || '',
                };
                if ('Amount' in sfobject) {
                    properties["sf:objectAmount"] = sfobject.Amount ? sfobject.Amount.toString() : null;
                }
                if (update) {
                    return Document.Update(input, { 'properties': properties });
                } else {
                    var docs = Repository.Query(null, {
                        'query': "SELECT * FROM Document WHERE ecm:isTrashed = 0 AND sf:objectId = '" + sfobject.Id + "' AND ecm:isVersion = 0 AND ecm:mixinType != 'HiddenInNavigation'",
                    });
                    if (docs.length > 0) {
                        return Repository.GetDocument(null, { 'value': docs[0].id });
                    } else {
                        return Document.Create(input, {
                            "type" : "Workspace",
                            "name" : sfobject.Name.replace(/[^A-Za-z0-9_.-]+/g, '-'),
                            "properties" : properties
                        });
                    }
                }
            }]]>
          </script>
        </scriptedOperation>
    
        <scriptedOperation id="Salesforce.LinkAsSource">
          <inputType>document</inputType>
          <outputType>document</outputType>
          <category>Salesforce</category>
          <param name="unlink" type="Boolean"/>
          <param name="record" type="Object"/>
          <script>
            <![CDATA[function run(input, params) {
                var sfobject = JSON.parse(params.record);
                Auth.LoginAs(null, {
                	'name': null
                }); // login as sys admin
                var doc = Salesforce.LinkDocument(input, {
                	'unlink': params.unlink,
                	'objectId': sfobject.Id 
                });
                Audit.LogEvent(input, {
                	'event': params.unlink ? 'DocumentUnlinkedFromSalesforceObject' : 'DocumentLinkedToSalesforceObject',
                	'category': 'Salesforce',
                	'comment': sfobject.Name + ' - ' +sfobject.Id 
                })
                return doc;
            }]]>
          </script>
        </scriptedOperation>
        
      </extension>
  • nuxeo-salesforce-core-2021.2.0.jar /OSGI-INF/business-metadata.xml
    <extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
    
    	<!--
    	An operation which is generating a HTML fragment displaying the business metadata    
    	-->
        <scriptedOperation id="Salesforce.RenderBusinessMetadata">
          <inputType>document</inputType>
          <outputType>blob</outputType>
          <category>Salesforce</category>
    	  <param name="lang" type="String"/>
    	        
          <script>
            <![CDATA[function run(input, params) {
            	// push the client language in the context
            	ctx.SALESFORCE_LANG = params.lang;
            	var blob = Render.Document(input, {
            		template: 'template:salesforce-business-metadata'        		
            	});
            	
            	return blob.getString(); // return the html fragment as a string
            }]]>
          </script>
        </scriptedOperation>
      </extension>
  • nuxeo-template-rendering-core-2021.63.8.jar /OSGI-INF/operations-contrib.xml
    <extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
    
        <scriptedOperation id="javascript.FilterTemplatesByType">
          <inputType>document</inputType>
          <outputType>documents</outputType>
          <category>javascript</category>
          <description>Filter templates according to the type of a given input document.</description>
          <script><![CDATA[
            function run(input, params) {
              return Repository.Query(null, {
                'query': 'select * from Document where ecm:mixinType = "Template" AND ecm:isTrashed = 0 AND tmpl:applicableTypes IN ( "all", "' + input['type'] + '") AND ecm:isVersion = 0'
              });
            }
          ]]></script>
        </scriptedOperation>
    
        <scriptedOperation id="javascript.RenderPdf">
          <inputType>document</inputType>
          <outputType>blob</outputType>
          <category>javascript</category>
          <param name="templateName" type="string"/>
          <param name="attach" type="boolean"/>
          <param name="templateData" type="string"/>
          <description>Render a document with a given template and converts it to PDF.</description>
          <script><![CDATA[
            function run(input, params) {
              var blob = TemplateProcessor.Render(input, {
                'templateName': params.templateName,
                'attach': params.attach || false,
                'templateData': params.templateData || null
              });
              return Blob.RunConverter(blob, {'converter': 'any2pdf'});
            }
          ]]></script>
        </scriptedOperation>
    
      </extension>